
#pragma once

#include <entt/entt.hpp>
#include "../layout/cell_command.hpp"
#include "../render/render.hpp"

#include "../canvas/CanvasWidget.h"
#include "../ecs/ecs.hpp"
#include "../ecs/stage.hpp"
#include "../ecs/utils.hpp"
#include "../input/input.hpp"
#include "./axis.hpp"

namespace qbe::render {
class Scene;
}
namespace qbe::canvas {
class CanvasWidget;
}

namespace qbe::axis {
using namespace input;

struct ZeroTag {};
struct MouseTag {};

// enum struct SelectBoxDirect : uint8_t {
//   None = 0,
//   Left = 1,
//   Right = 2,
// };

// enum struct SelectBoxDirect : uint8_t {
//   None = 0,
//   Left = 1,
//   Right = 2,
// };

// struct TransformEvent {
//   int code;
// };

struct DragAxisModel {
  // 鼠标拖拽按下像素位置
  bool drag;
  double drag_px{0}, drag_py{0};
};

struct AreaScaleModel {
  bool run{false};

  bool view_scale{false};
  bool is_exist_box{false};  // 框选框是否存在
  entt::entity entity_box;   // 框选对象
  double start_rx{0}, start_ry{0};
};

using vsg_group_t = vsg::ref_ptr<vsg::Group>;

void init_axis(entt::registry& reg, ecs::Query query, ecs::Commands commands, ecs::Res<vsg::ref_ptr<vsg::Options>> options);
void update_axis(entt::registry& reg, ecs::Query query, ecs::Bus& bus);
void drag_axis(ecs::Res<vsg::ref_ptr<HandleBundle>> res_handles, ecs::Res<Axis> res_axis, ecs::Res<DragAxisModel> res_model, ecs::Bus bus,
               ecs::Query query);
void view_scale(entt::registry& reg, ecs::Res<vsg::ref_ptr<HandleBundle>> res_handles, ecs::Res<Axis> res_axis, ecs::Res<AreaScaleModel> res_model);
void render_axis(entt::registry& reg, ecs::Query query, ecs::Res<canvas::CanvasWidget*> canvas);

class AxisPlugin : public ecs::Plugin {
 public:
  void build(ecs::App& app) override;
};
}  // namespace qbe::axis